package com.novax.ex.activity.provider.controller.inner;

import com.novax.ex.activity.infrastructure.entity.TaskData;
import com.novax.ex.activity.open.api.inner.TaskDataApi;
import com.novax.ex.activity.open.model.query.TaskDataQuery;
import com.novax.ex.activity.open.model.request.task.TaskDataRequest;
import com.novax.ex.activity.open.model.response.TaskDataResponse;
import com.novax.ex.activity.provider.controller.BaseActivityController;
import com.novax.ex.activity.provider.service.TaskDataService;
import com.novax.ex.common.constant.InternationalCode;
import com.novax.ex.common.results.ReturnResult;
import com.novax.ex.common.util.CopyUtils;
import com.novax.ex.common.util.PageUtil;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@RestController
public class TaskDataController extends BaseActivityController implements TaskDataApi {
    @Resource
    private TaskDataService taskDataService;


    @Override
    public ReturnResult<PageUtil<TaskDataResponse>> findPage(String language, TaskDataQuery query) {
        PageUtil<TaskDataResponse> page = new PageUtil<>(query);
        Map<String, Object> condition = new HashMap<>();
        condition.put("query", query);
        page.setCondition(condition);
        taskDataService.findPage(page, TaskDataResponse.class);
        return ReturnResult.success(getInternational(language, InternationalCode.QUERY_SUCCESS), page);
    }

    @Override
    public ReturnResult<Boolean> modify(String language, Long id, TaskDataRequest taskDataRequest) {
        TaskData taskData = CopyUtils.copyObject(taskDataRequest, TaskData.class);
        taskData.setId(id);
        taskData.setUpdater(taskDataRequest.getUserId());
        boolean flag = taskDataService.modifySelective(taskData);
        return flag ? ReturnResult.success(getInternational(language, InternationalCode.OPERATION_SUCCESS)) :
                ReturnResult.fail(getInternational(language, InternationalCode.OPERATION_ERROR));
    }
}
